//
//  PlatformViewCell.swift
//  d11
//
//  Created by peale on 2018/11/19.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
import Lottie
class PlatformViewCell: UITableViewCell {
    var iconImgView: UIImageView?
    var iconAnimationView : AnimationView?
    var titleLabel: UILabel?
    var isPay :Bool = false
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.iconImgView = UIImageView.init(image: imageNamed("login_logo"))
        self.contentView.addSubview(self.iconImgView!)
        self.iconImgView?.snp.makeConstraints{(make) in
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.centerX.equalToSuperview()
            make.top.equalTo(10)
        }
        self.iconAnimationView = AnimationView.init()
        self.contentView.addSubview(self.iconAnimationView!)
        self.iconAnimationView?.snp.makeConstraints{(make) in
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.centerX.equalToSuperview()
            make.top.equalTo(10)
        }
        self.titleLabel = UILabel.init()
        self.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        titleLabel?.textColor = HexRGBAlpha(0x747474, 1)
        titleLabel?.textAlignment = .center
        self.contentView.addSubview(self.titleLabel!)
        self.titleLabel?.snp.makeConstraints{(make) in
            make.width.equalToSuperview()
            make.height.equalTo(20)
            make.centerX.equalToSuperview()
           // make.top.equalTo((self.iconAnimationView?.snp.bottom)!).offset(10)
             make.top.equalTo(40)
        }
    }
    
    func setData(imgUrl:String,selImgUrl:String,title:String,isSelect:Bool) -> Void {
         titleLabel?.text = title
        if self.iconAnimationView != nil{
            self.iconAnimationView?.removeFromSuperview()
            self.iconAnimationView = nil
        }
        if isSelect == true {
         //   self.iconImgView?.sd_setImage(with: URL(string: selImgUrl), placeholderImage: imageNamed("icon_newhome_platform_zwt_bg_select"), options: .refreshCached, completed: nil)
//            self.iconAnimationView = AnimationView.init(contentsOf: URL(string: selImgUrl)!)
            self.iconAnimationView = AnimationView.init(url: URL(string: selImgUrl)!, closure: {
                down in
            })
            self.isPay = true
             self.titleLabel?.textColor = HexRGBAlpha(0xffc569, 1)
        }else{
            //self.iconImgView?.sd_setImage(with: URL(string: imgUrl), placeholderImage: imageNamed("icon_newhome_platform_zwt_bg_noselect"), options: .refreshCached, completed: nil)
//            self.iconAnimationView = AnimationView.init(contentsOf: URL(string: imgUrl)!)
            self.iconAnimationView = AnimationView.init(url: URL(string: selImgUrl)!, closure: {
                down in
            })
            self.titleLabel?.textColor = HexRGBAlpha(0x747474, 1)
        }
        self.contentView.addSubview(self.iconAnimationView!)
        self.iconAnimationView?.snp.makeConstraints{(make) in
            make.width.equalTo(30)
            make.height.equalTo(30)
            make.centerX.equalToSuperview()
            make.top.equalTo(10)
        }

        self.iconAnimationView?.play(completion: { (animationFinished) in
           
        })
        
        if self.iconAnimationView?.isAnimationPlaying == true{
            self.iconImgView?.isHidden = true
        }else{
            self.iconImgView?.isHidden = false
        }
    }
}
